package com.imooc.framework.stream;

import java.util.Comparator;
import java.util.DoubleSummaryStatistics;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ReducingDemo {

    public static void main(String[] args) {
//        Long count = Employee.getEmpList().stream().count();
//        Long count = (long) Employee.getEmpList().size();

        Stream<Employee> stream = Employee.getEmpList().parallelStream();
//
//        Long count1 = stream.count();
//        System.out.println("公司总人数" + count1);

//        Optional<Employee> optionalEmployee = stream.max(Comparator.comparing(Employee::getAge));
//        Optional<Employee> optionalEmployee = stream.collect(Collectors.maxBy(Comparator.comparing(Employee::getAge)));
//        Employee employee = optionalEmployee.get();
//        System.out.println("年龄最大的员工" + employee);

//        Optional<Employee> optionalEmployee = stream.min(Comparator.comparing(Employee::getAge));
//        Employee employee = optionalEmployee.get();
//        System.out.println("年龄最小的员工" + employee);

//        Double salarySum =  stream.collect(Collectors.summingDouble(Employee::getSalary));
//        Double salarySum = stream.mapToDouble(Employee::getSalary).sum();
//        System.out.println("薪资总和" + salarySum);

//        Double salarySum = stream.collect(Collectors.averagingDouble(Employee::getSalary));
//          OptionalDouble salarySum = stream.mapToDouble(Employee::getSalary).average();
//          System.out.printf("平均工资：%.2f\n",salarySum.getAsDouble());

//        DoubleSummaryStatistics s = stream.collect(Collectors.summarizingDouble(Employee::getSalary));
//        System.out.println("拿薪资的总人数" + s.getCount());
//        System.out.println("薪资总数" + s.getSum());
//        System.out.println("薪资最大值" + s.getMax());
//        System.out.println("薪资最小值" + s.getMin());
//        System.out.println("薪资平均值" + s.getAverage());

//        String nameList = stream.map(Employee::getName).collect(Collectors.joining(","));
//        System.out.println(nameList);
    }
}
